Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve AsyncApiAny api surface. #145

Merged
merged 5 commits into from
Feb 26, 2024
Merged

feat: improve AsyncApiAny api surface. #145

merged 5 commits into from
Feb 26, 2024

Conversation

VisualBean
Copy link
Collaborator

@VisualBean VisualBean commented Feb 26, 2024

About the PR

Fixes some issues with working with AsyncApiAny, figuring out the correct types etc.
Added new GetValue type methods for extracting expected values.
These use system.text.json to deserialize to T from the JsonNode type.

Added a static FromExtension method, to remove redundant type casting.
So instead of

if (TryGetValue(key, out IAsyncApiExtension extension))
{
  var myType = (extension as AsyncApiAny).GetValue<MyType>();
}

You do

if (TryGetValue(key, out IAsyncApiExtension extension))
{
  var myType = AsyncApiAny.FromExtensionOrDefault<MyType>(extension);
}

Added new constructor allowing for much simpler AsyncApiAny initialization, utlizing system.json.text to figure out the JsonNode type.

Changelog

  • Added: GetValue<T>()
  • Added: GetValueOrDefault<T>()
  • Added: TryGetValue<T>()
  • Added: static FromExtensionOrDefault<T>(IAsyncApiExtension extension)
  • Added: new constructor to allow for easier object creation.
  • Obsoleted: AsyncApiArray
  • Obsoleted: AsyncApiObject

@VisualBean VisualBean changed the title feat: Severely improve AsyncApiAny api. feat: severely improve AsyncApiAny api. Feb 26, 2024
@VisualBean VisualBean changed the title feat: severely improve AsyncApiAny api. feat: improve AsyncApiAny api surface. Feb 26, 2024
@VisualBean VisualBean merged commit 4899cde into main Feb 26, 2024
5 checks passed
@VisualBean VisualBean deleted the alex/fixasyncany branch February 26, 2024 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant